# reverse_count作为全局变量是一个元组，前两个元素代表列表中的逆序元素，最后一个元素是逆序
reverse_count = []


def compare(a, i, j):
    global reverse_count
    while i < j:
        if a[i] > a[j]:
            reverse_count.append((a[i], a[j]))
        j -= 1


def count_reverse_counts(a, i, j):
    global reverse_count
    if j - i == 1:
        if a[i] > a[j]:
            return a[i], a[j]
    else:
        compare(a, i, j)
        reverse_pair = count_reverse_counts(a, i+1, j)
        if reverse_pair is not None:
            reverse_count.append(reverse_pair)


if __name__ == '__main__':
    a = [2, 3, 1, -9]
    count_reverse_counts(a, 0, len(a) - 1)
    print(reverse_count)
